package org.jivesoftware.smack.packet;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class Privacy extends IQ
{
  private String activeName;
  private boolean declineActiveList = false;
  private boolean declineDefaultList = false;
  private String defaultName;
  private Map<String, List<PrivacyItem>> itemLists = new HashMap();

  public boolean changeDefaultList(String paramString)
  {
    int i;
    if (getItemLists().containsKey(paramString))
    {
      setDefaultName(paramString);
      i = 1;
    }
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public void deleteList(String paramString)
  {
    getItemLists().remove(paramString);
  }

  public void deletePrivacyList(String paramString)
  {
    getItemLists().remove(paramString);
    if ((getDefaultName() != null) && (paramString.equals(getDefaultName())))
      setDefaultName(null);
  }

  public String getActiveName()
  {
    return this.activeName;
  }

  public List<PrivacyItem> getActivePrivacyList()
  {
    List localList;
    if (getActiveName() == null)
      localList = null;
    while (true)
    {
      return localList;
      localList = (List)getItemLists().get(getActiveName());
    }
  }

  public String getChildElementXML()
  {
    Iterator localIterator1;
    Iterator localIterator2;
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<query xmlns=\"jabber:iq:privacy\">");
    if (isDeclineActiveList())
    {
      localStringBuilder.append("<active/>");
      if (!(isDeclineDefaultList()))
        break label119;
      localStringBuilder.append("<default/>");
    }
    while (true)
    {
      label119: 
      do
        while (true)
        {
          do
          {
            localIterator1 = getItemLists().entrySet().iterator();
            if (localIterator1.hasNext())
              break label148;
            localStringBuilder.append(getExtensionsXML());
            localStringBuilder.append("</query>");
            return localStringBuilder.toString();
          }
          while (getActiveName() == null);
          localStringBuilder.append("<active name=\"").append(getActiveName()).append("\"/>");
        }
      while (getDefaultName() == null);
      localStringBuilder.append("<default name=\"").append(getDefaultName()).append("\"/>");
    }
    label148: Map.Entry localEntry = (Map.Entry)localIterator1.next();
    String str = (String)localEntry.getKey();
    List localList = (List)localEntry.getValue();
    if (localList.isEmpty())
    {
      localStringBuilder.append("<list name=\"").append(str).append("\"/>");
      localIterator2 = localList.iterator();
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          do
            if (localIterator2.hasNext())
              break label270;
          while (localList.isEmpty());
          localStringBuilder.append("</list>");
        }
        localStringBuilder.append("<list name=\"").append(str).append("\">");
      }
      label270: localStringBuilder.append(((PrivacyItem)localIterator2.next()).toXML());
    }
  }

  public String getDefaultName()
  {
    return this.defaultName;
  }

  public List<PrivacyItem> getDefaultPrivacyList()
  {
    List localList;
    if (getDefaultName() == null)
      localList = null;
    while (true)
    {
      return localList;
      localList = (List)getItemLists().get(getDefaultName());
    }
  }

  public PrivacyItem getItem(String paramString, int paramInt)
  {
    Iterator localIterator = getPrivacyList(paramString).iterator();
    Object localObject = null;
    while (true)
    {
      PrivacyItem localPrivacyItem;
      do
      {
        if ((localObject != null) || (!(localIterator.hasNext())))
          return localObject;
        localPrivacyItem = (PrivacyItem)localIterator.next();
      }
      while (localPrivacyItem.getOrder() != paramInt);
      localObject = localPrivacyItem;
    }
  }

  public Map<String, List<PrivacyItem>> getItemLists()
  {
    return this.itemLists;
  }

  public List<PrivacyItem> getPrivacyList(String paramString)
  {
    return ((List)getItemLists().get(paramString));
  }

  public Set<String> getPrivacyListNames()
  {
    return this.itemLists.keySet();
  }

  public boolean isDeclineActiveList()
  {
    return this.declineActiveList;
  }

  public boolean isDeclineDefaultList()
  {
    return this.declineDefaultList;
  }

  public void setActiveName(String paramString)
  {
    this.activeName = paramString;
  }

  public List<PrivacyItem> setActivePrivacyList()
  {
    setActiveName(getDefaultName());
    return ((List)getItemLists().get(getActiveName()));
  }

  public void setDeclineActiveList(boolean paramBoolean)
  {
    this.declineActiveList = paramBoolean;
  }

  public void setDeclineDefaultList(boolean paramBoolean)
  {
    this.declineDefaultList = paramBoolean;
  }

  public void setDefaultName(String paramString)
  {
    this.defaultName = paramString;
  }

  public List setPrivacyList(String paramString, List<PrivacyItem> paramList)
  {
    getItemLists().put(paramString, paramList);
    return paramList;
  }
}